<template>
	<view class="body">
		<Rboy-upload-sfz :obverse-url="formData.obverseUrl" :reverse-url="formData.reverseUrl"
			@selectChange="sfz_chagne" @del="del_btn"></Rboy-upload-sfz>
		<view class="size">
			<view class="text">注意：</view>
			<view class="text">- 只支持 JPG 格式的图片，且图片中人像应清晰可见，无遮挡。</view>
			<view class="text">- 图片大小不超过3MB。</view>
		</view>
		<view class="submit" @click="handleSubmit">提交</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import RboyUploadSfz from "@/components/Rboy-upload-sfz/Rboy-upload-sfz.vue"
	export default {
		components: {
			RboyUploadSfz,
		},
		data() {
			return {
				userInfo: {},
				formData: {
					// 正面
					obverseUrl: "",
					// 反面
					reverseUrl: "",
				},
			}
		},
		onLoad(options) {
			this.userInfo = uni.getStorageSync('userInfo')
		},
		methods: {
			// 上传
			sfz_chagne(e) {
				if (e.name == "obverse") {
					this.formData.obverseUrl = e.tempFilePath
				} else if (e.name == "reverse") {
					this.formData.reverseUrl = e.tempFilePath
				}
			},
			// 删除
			del_btn(e) {
				if (e.name == "obverse") {
					this.formData.obverseUrl = ""
				} else if (e.name == "reverse") {
					this.formData.reverseUrl = ""
				}
			},
			//提交
			handleSubmit() {
				let rid = this.userInfo.rid
				this.$Api.userRealName({
					rid: this.userInfo.rid,
					idcard_image1: this.formData.obverseUrl.split(',')[1],
					idcard_image2: this.formData.reverseUrl.split(',')[1],
				}).then(res => {
					console.log('提交', res)
					if (res.msg == '身份验证成功') {
						this.$refs.uToast.show({
							title: res.msg,
							type: 'success',
						})
						uni.setStorage({
							key: "userInfoIs_auth", //添加键名
							data: true, //数据值
						})
						uni.navigateBack()
					} else {
						this.$refs.uToast.show({
							title: res.error,
							type: 'error',
						})
					}
				}, err => {
					console.log(err)
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.size{
		width: 90%;
		color: #666;
		text-align: center;
		margin: 80upx auto 0;
		.text{
			width: 100%;
			text-align: left;
			margin-bottom: 20upx;
			&:first-child{
				font-size: 30upx;
				color: #000;
			}
		}
	}
	.submit {
		width: 94%;
		padding: 30upx 0;
		background: #4094ff;
		border-radius: 60upx;
		text-align: center;
		color: #fff;
		position: fixed;
		bottom: 30upx;
		left: 3%;
		z-index: 99;
	}
</style>